package com.example.famhealing.timeline;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.famhealing.R;
 
//타임라인 중 '컨디션' 부분 리스트 어댑터
public class ConditionListAdapter extends ArrayAdapter<Condition_List_Data> {
 
    private ArrayList<Condition_List_Data> items;
    
    LinearLayout conditionBar;
    LinearLayout sideEffectBar;
    LinearLayout weightBar;
    LinearLayout temperBar;
    LinearLayout heartBar;
    LinearLayout pressureBar;
    LinearLayout medicineBar;
    LinearLayout memoBar;
 
    public ConditionListAdapter(Context context, int textViewResourceId,
            ArrayList<Condition_List_Data> items) {
        super(context, textViewResourceId, items);
        this.items = items; 
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.timeline_condition_list, null);
        }
        Condition_List_Data condition_list_data = items.get(position);
 
        if (condition_list_data != null) {
            
        	TextView tv_condition = (TextView) v.findViewById(R.id.timeline_condition);
        	TextView tv_sideEffects = (TextView) v.findViewById(R.id.timeline_sideEffects);
        	TextView tv_weight = (TextView) v.findViewById(R.id.timeline_weight);
        	TextView tv_temper = (TextView) v.findViewById(R.id.timeline_temper);
        	TextView tv_heart = (TextView) v.findViewById(R.id.timeline_heart);
        	TextView tv_pressure = (TextView) v.findViewById(R.id.timeline_pressure);
        	TextView tv_medicine = (TextView) v.findViewById(R.id.timeline_medicine);
            TextView tv_memo = (TextView) v.findViewById(R.id.timeline_memo);
            TextView tv_date = (TextView) v.findViewById(R.id.date);
            TextView tv_day = (TextView) v.findViewById(R.id.day);
            TextView tv_yearMonth = (TextView) v.findViewById(R.id.yearMonth);
            
            
            conditionBar = (LinearLayout) v.findViewById(R.id.conditionBar);
            sideEffectBar = (LinearLayout) v.findViewById(R.id.sideEffectBar);
            weightBar = (LinearLayout) v.findViewById(R.id.weightBar);
            temperBar = (LinearLayout) v.findViewById(R.id.temperBar);
            heartBar = (LinearLayout) v.findViewById(R.id.heartBar);
            pressureBar = (LinearLayout) v.findViewById(R.id.pressureBar);
            medicineBar = (LinearLayout) v.findViewById(R.id.medicineBar);
            memoBar = (LinearLayout) v.findViewById(R.id.memoBar);
            
            conditionBar.setBackgroundColor(Color.rgb(255,0,0));
            sideEffectBar.setBackgroundColor(Color.rgb(255,94,0));
            weightBar.setBackgroundColor(Color.rgb(255,187,0));
            temperBar.setBackgroundColor(Color.rgb(29,219,22));
            heartBar.setBackgroundColor(Color.rgb(0,216,255));
            pressureBar.setBackgroundColor(Color.rgb(1,0,255));
            medicineBar.setBackgroundColor(Color.rgb(255,0,127));
            memoBar.setBackgroundColor(Color.rgb(206,242,121));
            
            
            //각 TextView에 맞는 글을 넣어줌         
            tv_memo.setText(condition_list_data.getMemo());
            tv_medicine.setText(condition_list_data.getMedicine());
            tv_condition.setText(condition_list_data.getCondition());
            tv_sideEffects.setText(condition_list_data.getSideEffects());
            tv_heart.setText(condition_list_data.getHeart());
            tv_pressure.setText(condition_list_data.getPressure());
            tv_temper.setText(condition_list_data.getTemper());
            tv_weight.setText(condition_list_data.getWeight());
            tv_date.setText(condition_list_data.getDate());
            tv_day.setText(condition_list_data.getDay());
            tv_yearMonth.setText(condition_list_data.getYearMonth());
            
        }
 
        return v;
    }
}
 
class Condition_List_Data {
	private String memo;
    private String medicine;
    private String condition;
    private String sideEffects;
    private String weight;
    private String temper;
    private String heart;
    private String pressure;
    private String date;
    private String day;
    private String yearMonth;
    
    /*
    private String memoWriter;
    private String medicineWriter;
    private String feelingWriter;
    private String conditionWriter;
 	*/
    
    public Condition_List_Data(String condition, String sideEffects, String weight, String temper, String heart, String pressure, String medicine, String memo, String time) {
        this.setMemo(memo);
        this.setMedicine(medicine);
        this.setCondition(condition);
        this.setHeart(heart);
        this.setPressure(pressure);
        this.setSideEffects(sideEffects);
        this.setTemper(temper);
        this.setWeight(weight);
        
        GregorianCalendar cal = new GregorianCalendar();
        cal.set(Integer.parseInt(time.substring(0,4)), Integer.parseInt(time.substring(5,7))-1, Integer.parseInt(time.substring(8,10)));
        this.setDate(time.substring(8,10));
        this.setYearMonth(time.substring(5,7)+"/"+time.substring(0,4));
        
        switch(cal.get(Calendar.DAY_OF_WEEK))
        {
        case 1 : 
        	this.setDay("일");
        	break;
        case 2 : 
        	this.setDay("월");
        	break;
        case 3 :
        	this.setDay("화");
        	break;
        case 4 :
        	this.setDay("수");
        	break;
        case 5 :
        	this.setDay("목");
        	break;
        case 6 :
        	this.setDay("금");
        	break;
        case 7 :
        	this.setDay("토");
        	break;
        }
        
    }
    
    /*
    public Condition_List_Data(String memo, String medicine, String feeling, String condition
    		, String memoWriter, String medicineWriter, String feelingWriter, String conditionWriter) {
        this.setMemo(memo);
        this.setMedicine(medicine);
        this.setFeeling(feeling);
        this.setCondition(condition);
        
        this.setMemoWriter(memoWriter, medicineWriter, feelingWriter, conditionWriter);
    }
    */
    
    public String getMemo() {
    	return memo;
    }
 
    public void setMemo(String memo) {
    	this.memo = memo;
    }
    
    public String getMedicine() {
        return medicine;
    }
 
    public void setMedicine(String medicine) {
        this.medicine = medicine;
    }

    public String getCondition() {
        return condition;
    }
 
    public void setCondition(String condition) {
        this.condition = condition;
    }

	public String getSideEffects() {
		return sideEffects;
	}

	public void setSideEffects(String sideEffects) {
		this.sideEffects = sideEffects;
	}

	public String getWeight() {
		return weight;
	}

	public void setWeight(String weight) {
		this.weight = weight;
	}

	public String getTemper() {
		return temper;
	}

	public void setTemper(String temper) {
		this.temper = temper;
	}

	public String getHeart() {
		return heart;
	}

	public void setHeart(String heart) {
		this.heart = heart;
	}

	public String getPressure() {
		return pressure;
	}

	public void setPressure(String pressure) {
		this.pressure = pressure;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getDay() {
		return day;
	}

	public void setDay(String day) {
		this.day = day;
	}

	public String getYearMonth() {
		return yearMonth;
	}

	public void setYearMonth(String yearMonth) {
		this.yearMonth = yearMonth;
	}
    
    /* 해당 색으로 표시
    public void setColor(String memoWriter, String medicineWriter, String feelingWriter, String conditionWriter) {
    	if(memoWriter.equals("")) {
    		
    	}
    }
    */
    
}